﻿using System;
using System.Collections.Generic;
using System.Web.Http;
using LeHouse.Server.WebApi.Common;
using System.IO;
using LeHouse.Server.Dto;
using LeHouse.Server.Service;
using Aspose.Cells;

namespace LeHouse.Server.WebApi.Controllers
{
    public class ExaminationController : ApiController
    {
        /// <summary>
        /// 输出初审核报告书
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Examination/Thetrial")]
        public dynamic Thetrial([FromBody]string P_ReportNumber)
        {
            var obj = transmitHelper.bigByValueHelperByReportNumber(P_ReportNumber);
            jsonManager jm = new jsonManager();

            if (obj == null)
            {
                jm.code = 0;
                jm.msg = "该项目号下没有任何数据";
                return Json(jm);
            }

            if (!(obj.personal.T_State > 4))
            {
                jm.code = 0;
                jm.msg = "未通过初审，不能导出";
                return Json(jm);
            }

            string TemplateName = AppDomain.CurrentDomain.BaseDirectory
                + "Word\\Template\\抵押物初审意见书.doc";
            if (!File.Exists(TemplateName))
            {
                return "errer";
            }
            string path = AppDomain.CurrentDomain.BaseDirectory;

            Collateral_PersonalService personal = new Collateral_PersonalService();
            var d1 = personal.Select(p => p.T_ReportNumber == obj.T_ReportNumber).Find(p => p.T_ReportNumber == obj.T_ReportNumber);
            if (d1 == null)
            {
                jm.code = 0;
                jm.msg = "项目号查询出错";
                return Json(jm);
            }
            if (string.IsNullOrEmpty(d1.T_FinalAuditNumber))
            {
                var T_FinalAuditNumber = GetFinalAuditNumber.GETnumber(obj.T_ReportNumber);
                d1.T_FinalAuditNumber = T_FinalAuditNumber;
                personal.UpdateOnly(d1, p => p.T_FinalAuditNumber, p => p.T_ReportNumber == obj.T_ReportNumber);
            }

            string T_Name = "", T_Idcard = "", T_Phone = "", T_Name2="";
            foreach (var x in obj.borrower)
            {
                if (x.T_BorrowerID == obj.borrower[0].T_BorrowerID)
                {
                    T_Name += x.T_Name;
                    T_Idcard += x.T_Idcard;
                    T_Phone += x.T_Phone;
                    T_Name2 += x.T_Name;
                }
                else
                {
                    T_Name += "、" + x.T_Name;
                    T_Idcard += "、" + x.T_Idcard;
                    T_Phone += "、" + x.T_Phone;
                    T_Name2 += " " + x.T_Name;
                }
            }

            string T_DepartmentIDText="";
            var T_DepartmentIDTextList = transmitHelper.getDepartmentByDid(obj.personal.T_DepartmentID);
            if(T_DepartmentIDTextList!=null)
            {
                T_DepartmentIDText = T_DepartmentIDTextList.T_Dname;
            }
            //昌平网点--抵押物初审意见--任道胜 赵娜
            string SaveName = string.Format("Word\\Temp\\{0}--抵押物初审意见书--{1}.doc",T_DepartmentIDText,T_Name2);

            List<WordsTemp> lwt = new List<WordsTemp>();
            lwt.Add(new WordsTemp() { Name = "报告号", Value = d1.T_FinalAuditNumber });
            lwt.Add(new WordsTemp() { Name = "借款人", Value = T_Name });
            lwt.Add(new WordsTemp() { Name = "借款人身份证号", Value = T_Idcard });
            lwt.Add(new WordsTemp() { Name = "抵押物管理点(现场勘查所属部门)", Value = T_DepartmentIDText});
            lwt.Add(new WordsTemp() { Name = "抵押房屋地址", Value = obj.personal.T_Located });
            lwt.Add(new WordsTemp() { Name = "建筑面积", Value = obj.personal.T_Builtuparea.ToString() });
            lwt.Add(new WordsTemp() { Name = "价值时点", Value = obj.personal.T_ValuationDate==null?"--":((DateTime)obj.personal.T_ValuationDate).ToString("yyyy年MM月dd日") });
            lwt.Add(new WordsTemp() { Name = "评估总值", Value = obj.personal.T_Valueofassessment.ToString() });
            lwt.Add(new WordsTemp() { Name = "评估总值大写", Value = transmitHelper.chang(Convert.ToDouble(obj.personal.T_Valueofassessment)*10000) });
            lwt.Add(new WordsTemp() { Name = "最高抵押额", Value = obj.personal.T_MaximumMortgage.ToString() });
            lwt.Add(new WordsTemp() { Name = "最高抵押额大写", Value = transmitHelper.chang(Convert.ToDouble(obj.personal.T_MaximumMortgage)*10000) });
            lwt.Add(new WordsTemp() { Name = "抵押风险率", Value = obj.personal.T_Mortgageriskrate });
            lwt.Add(new WordsTemp() { Name = "房屋剩余使用年限", Value = obj.personal.T_Loanyear != null ? obj.personal.T_Loanyear : "[数据为空]" });
            lwt.Add(new WordsTemp() { Name = "买卖人姓名", Value = "李晓龙" });
            lwt.Add(new WordsTemp() { Name = "签约时间", Value = obj.personal.T_Date.ToString("yyyy年MM月dd日") });
            lwt.Add(new WordsTemp() { Name = "时间年月日", Value = DateTime.Now.ToString("yyyy年MM月dd日") });

            if (obj.businessContract != null)
            {
                lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同编号", Value = obj.businessContract.T_BusinessNumber });
                lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同签订时间", Value = obj.businessContract.T_BcDate!=null?((DateTime)obj.businessContract.T_BcDate).ToString("yyyy年MM月dd日"):"--" });
            }
            else
            {
                lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同编号", Value = "--" });
                lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同签订时间", Value ="--"});
            }

            CommonWords.Word(TemplateName, path + SaveName, lwt);
            jm.code = 1;
            jm.msg = SaveName;
            return Json(jm);
        }


        /// <summary>
        /// 输出终审报告书
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/Examination/lastAudit")]
        public dynamic lastAudit([FromBody]string T_ReportNumber)
        {
            var obj = transmitHelper.bigByValueHelperByReportNumber(T_ReportNumber);
            jsonManager jm = new jsonManager();

            if (obj == null)
            {
                jm.code = 0;
                jm.msg = "该项目号下没有任何数据";
                return Json(jm);
            }

            if (!(obj.personal.T_State > 4))
            {
                jm.code = 0;
                jm.msg = "未通过终审，不能导出";
                return Json(jm);
            }

            string path = AppDomain.CurrentDomain.BaseDirectory;
            
            Collateral_PersonalService personal = new Collateral_PersonalService();
            var d1 =personal.Select(p=>p.T_ReportNumber==obj.T_ReportNumber).Find(p=>p.T_ReportNumber==obj.T_ReportNumber);
            if(d1==null)
            {
                 jm.code = 0;
                jm.msg = "项目号查询出错";
                return Json(jm);
            }
            if(string.IsNullOrEmpty(d1.T_FinalAuditNumber))
            {
                var T_FinalAuditNumber = GetFinalAuditNumber.GETnumber(obj.T_ReportNumber);
                 d1.T_FinalAuditNumber = T_FinalAuditNumber;
                 personal.UpdateOnly(d1, p => p.T_FinalAuditNumber, p => p.T_ReportNumber == obj.T_ReportNumber);
            }
           
            if (obj.personal.T_ReportID == 400001)//--todo根据类型选择模板
            {
                string TemplateName = path + "Word\\Template\\昌平--模式1 2016-G-116-00065 任道胜 赵娜 正式评估报告.doc";
                if (!File.Exists(TemplateName))
                {
                    return "errer";
                }

                string T_Name = "", T_Idcard = "", T_Phone = "", T_Name2 = "";
                foreach (var x in obj.borrower)
                {
                    if (x.T_BorrowerID == obj.borrower[0].T_BorrowerID)
                    {
                        T_Name += x.T_Name;
                        T_Idcard += x.T_Idcard;
                        T_Phone += x.T_Phone;
                        T_Name2 += x.T_Name;
                    }
                    else
                    {
                        T_Name += "、" + x.T_Name;
                        T_Idcard += "、" + x.T_Idcard;
                        T_Phone += "、" + x.T_Phone;
                        T_Name2 += " " + x.T_Name;
                    }
                }

                string T_DepartmentIDText = "";
                var T_DepartmentIDTextList = transmitHelper.getDepartmentByDid(obj.personal.T_DepartmentID);
                if (T_DepartmentIDTextList != null)
                {
                    T_DepartmentIDText = T_DepartmentIDTextList.T_Dname;
                }

                string SaveName = string.Format("Word\\Temp\\" + DateTime.Now.ToString("yyyy年MM月") + "\\{0}--模式1 {1} {2} 正式评估报告.doc", T_DepartmentIDText, d1.T_FinalAuditNumber, T_Name2);

                List<WordsTemp> lwt = new List<WordsTemp>();
                lwt.Add(new WordsTemp() { Name = "估价报告编号", Value =d1.T_FinalAuditNumber });
                lwt.Add(new WordsTemp() { Name = "部门名称", Value = T_DepartmentIDText });
                lwt.Add(new WordsTemp() { Name = "房屋坐落", Value = obj.personal.T_Located });
                lwt.Add(new WordsTemp() { Name = "借款人", Value = T_Name });
                lwt.Add(new WordsTemp() { Name = "借款人身份证号", Value = T_Idcard });
                lwt.Add(new WordsTemp() { Name = "借款人联系电话", Value = T_Phone });
                lwt.Add(new WordsTemp() { Name = "当前日期", Value = DateTime.Now.ToString("yyyy年MM月dd日") });
                lwt.Add(new WordsTemp() { Name = "建筑面积", Value = obj.personal.T_Builtuparea.ToString() });
                lwt.Add(new WordsTemp() { Name = "房屋用途", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.personal.T_PurposeID) });
                lwt.Add(new WordsTemp() { Name = "评估单价", Value = obj.personal.T_ValuationPrice });
                lwt.Add(new WordsTemp() { Name = "评估总值", Value = obj.personal.T_Valueofassessment });
                lwt.Add(new WordsTemp() { Name = "评估总值大写", Value = transmitHelper.chang(Convert.ToDouble(obj.personal.T_Valueofassessment)*10000) });
                lwt.Add(new WordsTemp() { Name = "房屋剩余年限", Value = obj.personal.T_Loanyear });
                lwt.Add(new WordsTemp() { Name = "抵押风险率", Value = obj.personal.T_Mortgageriskrate });
                lwt.Add(new WordsTemp() { Name = "最高贷款抵押额", Value = obj.personal.T_MaximumMortgage });
                lwt.Add(new WordsTemp() { Name = "估价目的", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.personal.T_ValuationPurpose)) });
                lwt.Add(new WordsTemp() { Name = "估价时点", Value =Convert.ToDateTime(obj.personal.T_ValuationDate).ToString("yyyy年MM月dd日") });
                lwt.Add(new WordsTemp() { Name = "建成年代", Value = obj.personal.T_Activate });
                lwt.Add(new WordsTemp() { Name = "登记日期", Value = obj.personal.T_Date.ToString("yyyy年MM月dd日") });
                lwt.Add(new WordsTemp() { Name = "估价师", Value = transmitHelper.getStaffByStaffID(Convert.ToInt32(obj.personal.T_ValuationName)).T_Name });

                if (obj.indoor != null)
                {
                    string room = "";
                    if (obj.indoor.T_SeveralBedroom != null)
                    {
                        room += obj.indoor.T_SeveralBedroom + "室";
                    }
                    if (obj.indoor.T_Severaldrawing != null)
                    {
                        room += obj.indoor.T_Severaldrawing + "厅";
                    }
                    if (obj.indoor.T_Severalbathroom != null)
                    {
                        room += obj.indoor.T_Severalbathroom + "卫";
                    }
                    if (obj.indoor.T_SeveralKITCHEN != null)
                    {
                        room += obj.indoor.T_SeveralKITCHEN + "厨";
                    }
                    if (obj.indoor.T_Severalbalcony != null)
                    {
                        room += obj.indoor.T_Severalbalcony + "阳台";
                    }
                    if (obj.indoor.T_SeveralTerrace != null)
                    {
                        room += obj.indoor.T_SeveralTerrace + "露台";
                    }
                    if (obj.indoor.T_SeveralSmall != null)
                    {
                        room += obj.indoor.T_SeveralSmall + "小院";
                    }
                    lwt.Add(new WordsTemp() { Name = "二室一厅一卫一厨", Value = room });
                    lwt.Add(new WordsTemp() { Name = "总楼层", Value = obj.indoor.T_Floor == null ? "" : obj.indoor.T_Floor });
                    lwt.Add(new WordsTemp() { Name = "房屋实际用途", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_purposeID) });
                    lwt.Add(new WordsTemp() { Name = "朝向", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_OrientationID) });
                    lwt.Add(new WordsTemp() { Name = "所在楼层", Value = obj.indoor.T_Storey.ToString() });
                    lwt.Add(new WordsTemp() { Name = "住宅类型", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_ResidenceID) });
                    lwt.Add(new WordsTemp() { Name = "居室装修情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_HabitableID) });
                    lwt.Add(new WordsTemp() { Name = "卫生间装修情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_ToiletID) });
                    lwt.Add(new WordsTemp() { Name = "厨房装修情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_KitchenID) });
                    lwt.Add(new WordsTemp() { Name = "户内部分有关说明", Value = obj.indoor.T_Explain == null ? "" : obj.indoor.T_Explain });
                }

                if (obj.zone != null)
                {
                    lwt.Add(new WordsTemp() { Name = "交通便捷情况", Value = obj.zone.T_Traffic == null ? "" : obj.zone.T_Traffic });
                    lwt.Add(new WordsTemp() { Name = "自然人文环境情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_NatureID) });
                    lwt.Add(new WordsTemp() { Name = "居住社区成熟情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_DwellingID) });
                    lwt.Add(new WordsTemp() { Name = "基础设施配套情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_InfrastructureID) });
                    lwt.Add(new WordsTemp() { Name = "配套设施情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_SupportingID) });
                    lwt.Add(new WordsTemp() { Name = "有关说明", Value = obj.zone.T_Explain == null ? "" : obj.zone.T_Explain });
                }

                if (obj.community != null)
                {
                    lwt.Add(new WordsTemp() { Name = "项目案名", Value = obj.community.T_Project == null ? "" : obj.community.T_Project });
                    lwt.Add(new WordsTemp() { Name = "小区封闭性", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_CloseID) });
                    lwt.Add(new WordsTemp() { Name = "居住小区楼宇构成", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_BuildingID) });
                    lwt.Add(new WordsTemp() { Name = "景观及绿化", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_AfforestID) });
                    lwt.Add(new WordsTemp() { Name = "交通组织方式", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_TrafficZuzhiID) });
                    lwt.Add(new WordsTemp() { Name = "容积率", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_VolumeID) });
                    lwt.Add(new WordsTemp() { Name = "车位状况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_StallID) });
                    lwt.Add(new WordsTemp() { Name = "物业公司", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_PropertyID) });
                    lwt.Add(new WordsTemp() { Name = "小区状况-其他", Value = obj.community.T_Else == null ? "" : obj.community.T_Else });
                }

                if (obj.facility != null)
                {
                    lwt.Add(new WordsTemp() { Name = "房屋结构", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_StructureID) });
                    lwt.Add(new WordsTemp() { Name = "房屋类型", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_TypesID) });
                    lwt.Add(new WordsTemp() { Name = "外立面装饰", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_FacadeID) });
                    lwt.Add(new WordsTemp() { Name = "电梯", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_ElevatorID) });
                    lwt.Add(new WordsTemp() { Name = "供暖", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_HeatingID) });
                    lwt.Add(new WordsTemp() { Name = "供气", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_SupplyID) });
                    lwt.Add(new WordsTemp() { Name = "门禁", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_EntranceID) });
                    lwt.Add(new WordsTemp() { Name = "供水", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_WaterID) });
                    lwt.Add(new WordsTemp() { Name = "公共建筑部位-其他", Value = obj.facility.T_Else == null ? "" : obj.facility.T_Else });
                }

                if (obj.sitePicture.Count > 0)
                {
                    var T_Pictureurl_1 = obj.sitePicture.Find(p => p.T_SpName == "房屋所有权证照片");
                    if (T_Pictureurl_1 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "房屋所有权证照片", Value = T_Pictureurl_1.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "房屋所有权证照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_2 = obj.sitePicture.Find(p => p.T_SpName == "不动产权证书照片");
                    if (T_Pictureurl_2 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "不动产权证书照片", Value = T_Pictureurl_2.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "不动产权证书照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_3 = obj.sitePicture.Find(p => p.T_SpName == "税收完税证明照片");
                    if (T_Pictureurl_3 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "税收完税证明照片", Value = T_Pictureurl_3.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "税收完税证明照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_4 = obj.sitePicture.Find(p => p.T_SpName == "小区外部环境");
                    if (T_Pictureurl_4 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "小区外部环境照片", Value = T_Pictureurl_4.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "小区外部环境照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_5 = obj.sitePicture.Find(p => p.T_SpName == "小区入口");
                    if (T_Pictureurl_5 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "小区入口照片", Value = T_Pictureurl_5.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "小区入口照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_6 = obj.sitePicture.Find(p => p.T_SpName == "小区内部环境");
                    if (T_Pictureurl_6 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "小区内部环境", Value = T_Pictureurl_6.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "小区内部环境", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_7 = obj.sitePicture.Find(p => p.T_SpName == "物业地址（建筑楼牌）");
                    if (T_Pictureurl_7 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "物业地址（建筑楼牌）", Value = T_Pictureurl_7.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "物业地址（建筑楼牌）", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_8 = obj.sitePicture.Find(p => p.T_SpName == "单元门");
                    if (T_Pictureurl_8 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "单元门", Value = T_Pictureurl_8.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "单元门", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_9 = obj.sitePicture.Find(p => p.T_SpName == "入户门");
                    if (T_Pictureurl_9 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "入户门", Value = T_Pictureurl_9.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "入户门", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_10 = obj.sitePicture.Find(p => p.T_SpName == "居室(1)");
                    if (T_Pictureurl_10 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "居室照片1", Value = T_Pictureurl_10.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "居室照片1", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_11 = obj.sitePicture.Find(p => p.T_SpName == "建筑外观");
                    if (T_Pictureurl_11 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "建筑外观照片", Value = T_Pictureurl_11.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "建筑外观照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_12 = obj.sitePicture.Find(p => p.T_SpName == "厨房");
                    if (T_Pictureurl_12 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "厨房照片", Value = T_Pictureurl_12.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "厨房照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_13 = obj.sitePicture.Find(p => p.T_SpName == "卫生间");
                    if (T_Pictureurl_13 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "卫生间照片", Value = T_Pictureurl_13.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "卫生间照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_14 = obj.sitePicture.Find(p => p.T_SpName == "阳台");
                    if (T_Pictureurl_14 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "阳台照片", Value = T_Pictureurl_14.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "阳台照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_15 = obj.sitePicture.Find(p => p.T_SpName == "客厅");
                    if (T_Pictureurl_15 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "客厅", Value = T_Pictureurl_15.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "客厅", Value = "暂无照片", Type = FileFormat.String });
                    }

                }

                if (obj.ownership!=null)
                {
                    lwt.Add(new WordsTemp() { Name = "房屋所有权证书编号", Value = string.Format("《房屋所有权证》({0})", obj.ownership.T_OwneNumber) });
                    lwt.Add(new WordsTemp() { Name = "产权人", Value =obj.ownership.T_ProductionName});
                    lwt.Add(new WordsTemp() { Name = "共有情况", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.ownership.T_CommonSituation)) });
                    lwt.Add(new WordsTemp() { Name = "房屋产别", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.ownership.T_HousingProduction)) });
                    lwt.Add(new WordsTemp() { Name = "来源属性", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.ownership.T_SourceAttribute)) });
                    lwt.Add(new WordsTemp() { Name = "专有建筑面积", Value = obj.ownership.T_ProperBuiltUpArea.ToString()});
                    lwt.Add(new WordsTemp() { Name = "房产证登记时间", Value = obj.ownership.T_ProductionDate!=null?((DateTime)obj.ownership.T_ProductionDate).ToString("yyyy年MM月dd日"):"--" });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "房屋所有权证书编号", Value = ""});
                }

                if(obj.realestate!=null)
                {
                    lwt.Add(new WordsTemp() { Name = "不动产权证书编号", Value = string.Format("《不动产权证书》（{0}）", obj.realestate.T_RealNumber) });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "不动产权证书编号", Value = "" });
                }

                if(obj.taxcertificate!=null)
                {
                    lwt.Add(new WordsTemp() { Name = "国税收完税证明编号", Value = string.Format("中华人民共和国税收完税证明（141）{0}", obj.taxcertificate.T_TaxNumber) });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "国税收完税证明编号", Value =""});
                }

                if (obj.businessContract != null)
                {
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同编号", Value = obj.businessContract.T_BusinessNumber });
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同签订时间", Value = obj.businessContract.T_BcDate != null ? ((DateTime)obj.businessContract.T_BcDate).ToString("yyyy年MM月dd日") : "--" });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同编号", Value = "--" });
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同签订时间", Value = "--" });
                }

                CommonWords.Word(TemplateName, path + SaveName, lwt);
                jm.code = 1;
                jm.msg = SaveName;
                return Json(jm);
            }
            else if (obj.personal.T_ReportID == 400002)
            {
                string TemplateName = path + "Word\\Template\\中关村--模式2 2016-G-133-00011号 李胜男 正式评估报告.doc";
                if (!File.Exists(TemplateName))
                {
                    return "errer";
                }

                string T_Name = "", T_Idcard = "", T_Phone = "", T_Name2 = "";
                foreach (var x in obj.borrower)
                {
                    if (x.T_BorrowerID == obj.borrower[0].T_BorrowerID)
                    {
                        T_Name += x.T_Name;
                        T_Idcard += x.T_Idcard;
                        T_Phone += x.T_Phone;
                        T_Name2 += x.T_Name;
                    }
                    else
                    {
                        T_Name += "、" + x.T_Name;
                        T_Idcard += "、" + x.T_Idcard;
                        T_Phone += "、" + x.T_Phone;
                        T_Name2 += " " + x.T_Name;
                    }
                }

                string T_DepartmentIDText = "";
                var T_DepartmentIDTextList = transmitHelper.getDepartmentByDid(obj.personal.T_DepartmentID);
                if (T_DepartmentIDTextList != null)
                {
                    T_DepartmentIDText = T_DepartmentIDTextList.T_Dname;
                }

                string SaveName = string.Format("Word\\Temp\\" + DateTime.Now.ToString("yyyy年MM月") + "\\{0}--模式2 {1}号 {2} 正式评估报告.doc", T_DepartmentIDText, d1.T_FinalAuditNumber, T_Name2);

                List<WordsTemp> lwt = new List<WordsTemp>();
                lwt.Add(new WordsTemp() { Name = "估价报告编号", Value = d1.T_FinalAuditNumber });
                lwt.Add(new WordsTemp() { Name = "部门名称", Value = T_DepartmentIDText });
                lwt.Add(new WordsTemp() { Name = "房屋坐落", Value = obj.personal.T_Located });
                lwt.Add(new WordsTemp() { Name = "借款人", Value = T_Name });
                lwt.Add(new WordsTemp() { Name = "借款人身份证号", Value = T_Idcard });
                lwt.Add(new WordsTemp() { Name = "借款人联系电话", Value = T_Phone });
                lwt.Add(new WordsTemp() { Name = "当前日期", Value = DateTime.Now.ToString("yyyy年MM月dd日") });
                lwt.Add(new WordsTemp() { Name = "建筑面积", Value = obj.personal.T_Builtuparea.ToString() });
                lwt.Add(new WordsTemp() { Name = "房屋用途", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.personal.T_PurposeID) });
                lwt.Add(new WordsTemp() { Name = "评估单价", Value = obj.personal.T_ValuationPrice });
                lwt.Add(new WordsTemp() { Name = "评估总值", Value = obj.personal.T_Valueofassessment });
                lwt.Add(new WordsTemp() { Name = "评估总值大写", Value = transmitHelper.chang(Convert.ToDouble(obj.personal.T_Valueofassessment)*10000) });
                lwt.Add(new WordsTemp() { Name = "房屋剩余年限", Value = obj.personal.T_Loanyear });
                lwt.Add(new WordsTemp() { Name = "抵押风险率", Value = obj.personal.T_Mortgageriskrate });
                lwt.Add(new WordsTemp() { Name = "最高贷款抵押额", Value = obj.personal.T_MaximumMortgage });
                lwt.Add(new WordsTemp() { Name = "估价目的", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.personal.T_ValuationPurpose)) });
                lwt.Add(new WordsTemp() { Name = "估价时点", Value = Convert.ToDateTime(obj.personal.T_ValuationDate).ToString("yyyy年MM月dd日") });
                lwt.Add(new WordsTemp() { Name = "建成年代", Value = obj.personal.T_Activate });
                lwt.Add(new WordsTemp() { Name = "登记日期", Value = obj.personal.T_Date.ToString("yyyy年MM月dd日") });
                lwt.Add(new WordsTemp() { Name = "估价师", Value = transmitHelper.getStaffByStaffID(Convert.ToInt32(obj.personal.T_ValuationName)).T_Name });

                if (obj.indoor != null)
                {
                    string room = "";
                    if (obj.indoor.T_SeveralBedroom != null)
                    {
                        room += obj.indoor.T_SeveralBedroom + "室";
                    }
                    if (obj.indoor.T_Severaldrawing != null)
                    {
                        room += obj.indoor.T_Severaldrawing + "厅";
                    }
                    if (obj.indoor.T_Severalbathroom != null)
                    {
                        room += obj.indoor.T_Severalbathroom + "卫";
                    }
                    if (obj.indoor.T_SeveralKITCHEN != null)
                    {
                        room += obj.indoor.T_SeveralKITCHEN + "厨";
                    }
                    if (obj.indoor.T_Severalbalcony != null)
                    {
                        room += obj.indoor.T_Severalbalcony + "阳台";
                    }
                    if (obj.indoor.T_SeveralTerrace != null)
                    {
                        room += obj.indoor.T_SeveralTerrace + "露台";
                    }
                    if (obj.indoor.T_SeveralSmall != null)
                    {
                        room += obj.indoor.T_SeveralSmall + "小院";
                    }
                    lwt.Add(new WordsTemp() { Name = "二室一厅一卫一厨", Value = room });
                    lwt.Add(new WordsTemp() { Name = "总楼层", Value = obj.indoor.T_Floor == null ? "" : obj.indoor.T_Floor });
                    lwt.Add(new WordsTemp() { Name = "房屋实际用途", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_purposeID) });
                    lwt.Add(new WordsTemp() { Name = "朝向", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_OrientationID) });
                    lwt.Add(new WordsTemp() { Name = "所在楼层", Value = obj.indoor.T_Storey.ToString() });
                    lwt.Add(new WordsTemp() { Name = "住宅类型", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_ResidenceID) });
                    lwt.Add(new WordsTemp() { Name = "居室装修情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_HabitableID) });
                    lwt.Add(new WordsTemp() { Name = "卫生间装修情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_ToiletID) });
                    lwt.Add(new WordsTemp() { Name = "厨房装修情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_KitchenID) });
                    lwt.Add(new WordsTemp() { Name = "户内部分有关说明", Value = obj.indoor.T_Explain == null ? "" : obj.indoor.T_Explain });
                }

                if (obj.zone != null)
                {
                    lwt.Add(new WordsTemp() { Name = "交通便捷情况", Value = obj.zone.T_Traffic == null ? "" : obj.zone.T_Traffic });
                    lwt.Add(new WordsTemp() { Name = "自然人文环境情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_NatureID) });
                    lwt.Add(new WordsTemp() { Name = "居住社区成熟情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_DwellingID) });
                    lwt.Add(new WordsTemp() { Name = "基础设施配套情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_InfrastructureID) });
                    lwt.Add(new WordsTemp() { Name = "配套设施情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_SupportingID) });
                    lwt.Add(new WordsTemp() { Name = "有关说明", Value = obj.zone.T_Explain == null ? "" : obj.zone.T_Explain });
                }

                if (obj.community != null)
                {
                    lwt.Add(new WordsTemp() { Name = "项目案名", Value = obj.community.T_Project == null ? "" : obj.community.T_Project });
                    lwt.Add(new WordsTemp() { Name = "小区封闭性", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_CloseID) });
                    lwt.Add(new WordsTemp() { Name = "居住小区楼宇构成", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_BuildingID) });
                    lwt.Add(new WordsTemp() { Name = "景观及绿化", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_AfforestID) });
                    lwt.Add(new WordsTemp() { Name = "交通组织方式", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_TrafficZuzhiID) });
                    lwt.Add(new WordsTemp() { Name = "容积率", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_VolumeID) });
                    lwt.Add(new WordsTemp() { Name = "车位状况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_StallID) });
                    lwt.Add(new WordsTemp() { Name = "物业公司", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_PropertyID) });
                    lwt.Add(new WordsTemp() { Name = "小区状况-其他", Value = obj.community.T_Else == null ? "" : obj.community.T_Else });
                }

                if (obj.facility != null)
                {
                    lwt.Add(new WordsTemp() { Name = "房屋结构", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_StructureID) });
                    lwt.Add(new WordsTemp() { Name = "房屋类型", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_TypesID) });
                    lwt.Add(new WordsTemp() { Name = "外立面装饰", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_FacadeID) });
                    lwt.Add(new WordsTemp() { Name = "电梯", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_ElevatorID) });
                    lwt.Add(new WordsTemp() { Name = "供暖", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_HeatingID) });
                    lwt.Add(new WordsTemp() { Name = "供气", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_SupplyID) });
                    lwt.Add(new WordsTemp() { Name = "门禁", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_EntranceID) });
                    lwt.Add(new WordsTemp() { Name = "供水", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_WaterID) });
                    lwt.Add(new WordsTemp() { Name = "公共建筑部位-其他", Value = obj.facility.T_Else == null ? "" : obj.facility.T_Else });
                }

                if (obj.sitePicture.Count > 0)
                {
                    var T_Pictureurl_1 = obj.sitePicture.Find(p => p.T_SpName == "房屋所有权证照片");
                    if (T_Pictureurl_1 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "房屋所有权证照片", Value = T_Pictureurl_1.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "房屋所有权证照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_2 = obj.sitePicture.Find(p => p.T_SpName == "不动产权证书照片");
                    if (T_Pictureurl_2 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "不动产权证书照片", Value = T_Pictureurl_2.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "不动产权证书照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_3 = obj.sitePicture.Find(p => p.T_SpName == "税收完税证明照片");
                    if (T_Pictureurl_3 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "税收完税证明照片", Value = T_Pictureurl_3.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "税收完税证明照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_4 = obj.sitePicture.Find(p => p.T_SpName == "小区外部环境");
                    if (T_Pictureurl_4 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "小区外部环境照片", Value = T_Pictureurl_4.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "小区外部环境照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_5 = obj.sitePicture.Find(p => p.T_SpName == "小区入口");
                    if (T_Pictureurl_5 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "小区入口照片", Value = T_Pictureurl_5.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "小区入口照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_6 = obj.sitePicture.Find(p => p.T_SpName == "小区内部环境");
                    if (T_Pictureurl_6 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "小区内部环境", Value = T_Pictureurl_6.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "小区内部环境", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_7 = obj.sitePicture.Find(p => p.T_SpName == "物业地址（建筑楼牌）");
                    if (T_Pictureurl_7 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "物业地址（建筑楼牌）", Value = T_Pictureurl_7.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "物业地址（建筑楼牌）", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_8 = obj.sitePicture.Find(p => p.T_SpName == "单元门");
                    if (T_Pictureurl_8 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "单元门", Value = T_Pictureurl_8.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "单元门", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_9 = obj.sitePicture.Find(p => p.T_SpName == "入户门");
                    if (T_Pictureurl_9 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "入户门", Value = T_Pictureurl_9.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "入户门", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_10 = obj.sitePicture.Find(p => p.T_SpName == "居室(1)");
                    if (T_Pictureurl_10 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "居室照片1", Value = T_Pictureurl_10.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "居室照片1", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_11 = obj.sitePicture.Find(p => p.T_SpName == "建筑外观");
                    if (T_Pictureurl_11 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "建筑外观照片", Value = T_Pictureurl_11.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "建筑外观照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_12 = obj.sitePicture.Find(p => p.T_SpName == "厨房");
                    if (T_Pictureurl_12 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "厨房照片", Value = T_Pictureurl_12.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "厨房照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_13 = obj.sitePicture.Find(p => p.T_SpName == "卫生间");
                    if (T_Pictureurl_13 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "卫生间照片", Value = T_Pictureurl_13.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "卫生间照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_14 = obj.sitePicture.Find(p => p.T_SpName == "阳台");
                    if (T_Pictureurl_14 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "阳台照片", Value = T_Pictureurl_14.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "阳台照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_15 = obj.sitePicture.Find(p => p.T_SpName == "客厅");
                    if (T_Pictureurl_15 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "客厅", Value = T_Pictureurl_15.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "客厅", Value = "暂无照片", Type = FileFormat.String });
                    }

                }

                if (obj.ownership != null)
                {
                    lwt.Add(new WordsTemp() { Name = "房屋所有权证书编号", Value = string.Format("《房屋所有权证》({0})", obj.ownership.T_OwneNumber) });
                    lwt.Add(new WordsTemp() { Name = "产权人", Value = obj.ownership.T_ProductionName });
                    lwt.Add(new WordsTemp() { Name = "共有情况", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.ownership.T_CommonSituation)) });
                    lwt.Add(new WordsTemp() { Name = "房屋产别", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.ownership.T_HousingProduction)) });
                    lwt.Add(new WordsTemp() { Name = "来源属性", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.ownership.T_SourceAttribute)) });
                    lwt.Add(new WordsTemp() { Name = "专有建筑面积", Value = obj.ownership.T_ProperBuiltUpArea.ToString() });
                    lwt.Add(new WordsTemp() { Name = "房产证登记时间", Value = obj.ownership.T_ProductionDate != null ? ((DateTime)obj.ownership.T_ProductionDate).ToString("yyyy年MM月dd日") : "--" });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "房屋所有权证书编号", Value = "" });
                }

                if (obj.realestate != null)
                {
                    lwt.Add(new WordsTemp() { Name = "不动产权证书编号", Value = string.Format("《不动产权证书》（{0}）", obj.realestate.T_RealNumber) });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "不动产权证书编号", Value = "" });
                }

                if (obj.taxcertificate != null)
                {
                    lwt.Add(new WordsTemp() { Name = "国税收完税证明编号", Value = string.Format("中华人民共和国税收完税证明（141）{0}", obj.taxcertificate.T_TaxNumber) });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "国税收完税证明编号", Value = "" });
                }

                if (obj.businessContract != null)
                {
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同编号", Value = obj.businessContract.T_BusinessNumber });
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同签订时间", Value = obj.businessContract.T_BcDate != null ? ((DateTime)obj.businessContract.T_BcDate).ToString("yyyy年MM月dd日") : "--" });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同编号", Value = "--" });
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同签订时间", Value = "--" });
                }

                CommonWords.Word(TemplateName, path + SaveName, lwt);
                jm.code = 1;
                jm.msg = SaveName;
                return Json(jm);
            }
            else if (obj.personal.T_ReportID == 400003)
            {
                string TemplateName = path + "Word\\Template\\延庆--模式3 2016-G-118-00026-张庆 正式评估报告.doc";
                if (!File.Exists(TemplateName))
                {
                    return "errer";
                }

                string T_Name = "", T_Idcard = "", T_Phone = "", T_Name2 = "";
                foreach (var x in obj.borrower)
                {
                    if (x.T_BorrowerID == obj.borrower[0].T_BorrowerID)
                    {
                        T_Name += x.T_Name;
                        T_Idcard += x.T_Idcard;
                        T_Phone += x.T_Phone;
                        T_Name2 += x.T_Name;
                    }
                    else
                    {
                        T_Name += "、" + x.T_Name;
                        T_Idcard += "、" + x.T_Idcard;
                        T_Phone += "、" + x.T_Phone;
                        T_Name2 += " " + x.T_Name;
                    }
                }

                string T_DepartmentIDText = "";
                var T_DepartmentIDTextList = transmitHelper.getDepartmentByDid(obj.personal.T_DepartmentID);
                if (T_DepartmentIDTextList != null)
                {
                    T_DepartmentIDText = T_DepartmentIDTextList.T_Dname;
                }

                string SaveName = string.Format("Word\\Temp\\" + DateTime.Now.ToString("yyyy年MM月") + "\\{0}--模式3 {1}-{2} 正式评估报告.doc", T_DepartmentIDText, d1.T_FinalAuditNumber, T_Name2);

                List<WordsTemp> lwt = new List<WordsTemp>();
                lwt.Add(new WordsTemp() { Name = "估价报告编号", Value = d1.T_FinalAuditNumber });
                lwt.Add(new WordsTemp() { Name = "部门名称", Value =T_DepartmentIDText });
                lwt.Add(new WordsTemp() { Name = "房屋坐落", Value = obj.personal.T_Located });
                lwt.Add(new WordsTemp() { Name = "借款人", Value = T_Name });
                lwt.Add(new WordsTemp() { Name = "借款人身份证号", Value = T_Idcard });
                lwt.Add(new WordsTemp() { Name = "借款人联系电话", Value = T_Phone });
                lwt.Add(new WordsTemp() { Name = "当前日期", Value = DateTime.Now.ToString("yyyy年MM月dd日") });
                lwt.Add(new WordsTemp() { Name = "建筑面积", Value = obj.personal.T_Builtuparea.ToString() });
                lwt.Add(new WordsTemp() { Name = "房屋用途", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.personal.T_PurposeID) });
                lwt.Add(new WordsTemp() { Name = "评估单价", Value = obj.personal.T_ValuationPrice });
                lwt.Add(new WordsTemp() { Name = "评估总值", Value = obj.personal.T_Valueofassessment });
                lwt.Add(new WordsTemp() { Name = "评估总值大写", Value = transmitHelper.chang(Convert.ToDouble(obj.personal.T_Valueofassessment)*10000) });
                lwt.Add(new WordsTemp() { Name = "房屋剩余年限", Value = obj.personal.T_Loanyear });
                lwt.Add(new WordsTemp() { Name = "抵押风险率", Value = obj.personal.T_Mortgageriskrate });
                lwt.Add(new WordsTemp() { Name = "最高贷款抵押额", Value = obj.personal.T_MaximumMortgage });
                lwt.Add(new WordsTemp() { Name = "估价目的", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.personal.T_ValuationPurpose)) });
                lwt.Add(new WordsTemp() { Name = "估价时点", Value = Convert.ToDateTime(obj.personal.T_ValuationDate).ToString("yyyy年MM月dd日") });
                lwt.Add(new WordsTemp() { Name = "建成年代", Value = obj.personal.T_Activate });
                lwt.Add(new WordsTemp() { Name = "登记日期", Value = obj.personal.T_Date.ToString("yyyy年MM月dd日") });
                lwt.Add(new WordsTemp() { Name = "估价师", Value = transmitHelper.getStaffByStaffID(Convert.ToInt32(obj.personal.T_ValuationName)).T_Name });

                if (obj.indoor != null)
                {
                    string room = "";
                    if (obj.indoor.T_SeveralBedroom != null)
                    {
                        room += obj.indoor.T_SeveralBedroom + "室";
                    }
                    if (obj.indoor.T_Severaldrawing != null)
                    {
                        room += obj.indoor.T_Severaldrawing + "厅";
                    }
                    if (obj.indoor.T_Severalbathroom != null)
                    {
                        room += obj.indoor.T_Severalbathroom + "卫";
                    }
                    if (obj.indoor.T_SeveralKITCHEN != null)
                    {
                        room += obj.indoor.T_SeveralKITCHEN + "厨";
                    }
                    if (obj.indoor.T_Severalbalcony != null)
                    {
                        room += obj.indoor.T_Severalbalcony + "阳台";
                    }
                    if (obj.indoor.T_SeveralTerrace != null)
                    {
                        room += obj.indoor.T_SeveralTerrace + "露台";
                    }
                    if (obj.indoor.T_SeveralSmall != null)
                    {
                        room += obj.indoor.T_SeveralSmall + "小院";
                    }
                    lwt.Add(new WordsTemp() { Name = "二室一厅一卫一厨", Value = room });
                    lwt.Add(new WordsTemp() { Name = "总楼层", Value = obj.indoor.T_Floor == null ? "" : obj.indoor.T_Floor });
                    lwt.Add(new WordsTemp() { Name = "房屋实际用途", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_purposeID) });
                    lwt.Add(new WordsTemp() { Name = "朝向", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_OrientationID) });
                    lwt.Add(new WordsTemp() { Name = "所在楼层", Value = obj.indoor.T_Storey.ToString() });
                    lwt.Add(new WordsTemp() { Name = "住宅类型", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_ResidenceID) });
                    lwt.Add(new WordsTemp() { Name = "居室装修情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_HabitableID) });
                    lwt.Add(new WordsTemp() { Name = "卫生间装修情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_ToiletID) });
                    lwt.Add(new WordsTemp() { Name = "厨房装修情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.indoor.T_KitchenID) });
                    lwt.Add(new WordsTemp() { Name = "户内部分有关说明", Value = obj.indoor.T_Explain == null ? "" : obj.indoor.T_Explain });
                }

                if (obj.zone != null)
                {
                    lwt.Add(new WordsTemp() { Name = "交通便捷情况", Value = obj.zone.T_Traffic == null ? "" : obj.zone.T_Traffic });
                    lwt.Add(new WordsTemp() { Name = "自然人文环境情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_NatureID) });
                    lwt.Add(new WordsTemp() { Name = "居住社区成熟情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_DwellingID) });
                    lwt.Add(new WordsTemp() { Name = "基础设施配套情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_InfrastructureID) });
                    lwt.Add(new WordsTemp() { Name = "配套设施情况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.zone.T_SupportingID) });
                    lwt.Add(new WordsTemp() { Name = "有关说明", Value = obj.zone.T_Explain == null ? "" : obj.zone.T_Explain });
                }

                if (obj.community != null)
                {
                    lwt.Add(new WordsTemp() { Name = "项目案名", Value = obj.community.T_Project == null ? "" : obj.community.T_Project });
                    lwt.Add(new WordsTemp() { Name = "小区封闭性", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_CloseID) });
                    lwt.Add(new WordsTemp() { Name = "居住小区楼宇构成", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_BuildingID) });
                    lwt.Add(new WordsTemp() { Name = "景观及绿化", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_AfforestID) });
                    lwt.Add(new WordsTemp() { Name = "交通组织方式", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_TrafficZuzhiID) });
                    lwt.Add(new WordsTemp() { Name = "容积率", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_VolumeID) });
                    lwt.Add(new WordsTemp() { Name = "车位状况", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_StallID) });
                    lwt.Add(new WordsTemp() { Name = "物业公司", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.community.T_PropertyID) });
                    lwt.Add(new WordsTemp() { Name = "小区状况-其他", Value = obj.community.T_Else == null ? "" : obj.community.T_Else });
                }

                if (obj.facility != null)
                {
                    lwt.Add(new WordsTemp() { Name = "房屋结构", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_StructureID) });
                    lwt.Add(new WordsTemp() { Name = "房屋类型", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_TypesID) });
                    lwt.Add(new WordsTemp() { Name = "外立面装饰", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_FacadeID) });
                    lwt.Add(new WordsTemp() { Name = "电梯", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_ElevatorID) });
                    lwt.Add(new WordsTemp() { Name = "供暖", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_HeatingID) });
                    lwt.Add(new WordsTemp() { Name = "供气", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_SupplyID) });
                    lwt.Add(new WordsTemp() { Name = "门禁", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_EntranceID) });
                    lwt.Add(new WordsTemp() { Name = "供水", Value = transmitHelper.getDictionaryNameByDictionaryID(obj.facility.T_WaterID) });
                    lwt.Add(new WordsTemp() { Name = "公共建筑部位-其他", Value = obj.facility.T_Else == null ? "" : obj.facility.T_Else });
                }

                if (obj.sitePicture.Count > 0)
                {
                    var T_Pictureurl_1 = obj.sitePicture.Find(p => p.T_SpName == "房屋所有权证照片");
                    if (T_Pictureurl_1 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "房屋所有权证照片", Value = T_Pictureurl_1.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "房屋所有权证照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_2 = obj.sitePicture.Find(p => p.T_SpName == "不动产权证书照片");
                    if (T_Pictureurl_2 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "不动产权证书照片", Value = T_Pictureurl_2.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "不动产权证书照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_3 = obj.sitePicture.Find(p => p.T_SpName == "税收完税证明照片");
                    if (T_Pictureurl_3 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "税收完税证明照片", Value = T_Pictureurl_3.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "税收完税证明照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_4 = obj.sitePicture.Find(p => p.T_SpName == "小区外部环境");
                    if (T_Pictureurl_4 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "小区外部环境照片", Value = T_Pictureurl_4.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "小区外部环境照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_5 = obj.sitePicture.Find(p => p.T_SpName == "小区入口");
                    if (T_Pictureurl_5 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "小区入口照片", Value = T_Pictureurl_5.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "小区入口照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_6 = obj.sitePicture.Find(p => p.T_SpName == "小区内部环境");
                    if (T_Pictureurl_6 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "小区内部环境", Value = T_Pictureurl_6.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "小区内部环境", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_7 = obj.sitePicture.Find(p => p.T_SpName == "物业地址（建筑楼牌）");
                    if (T_Pictureurl_7 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "物业地址（建筑楼牌）", Value = T_Pictureurl_7.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "物业地址（建筑楼牌）", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_8 = obj.sitePicture.Find(p => p.T_SpName == "单元门");
                    if (T_Pictureurl_8 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "单元门", Value = T_Pictureurl_8.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "单元门", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_9 = obj.sitePicture.Find(p => p.T_SpName == "入户门");
                    if (T_Pictureurl_9 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "入户门", Value = T_Pictureurl_9.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "入户门", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_10 = obj.sitePicture.Find(p => p.T_SpName == "居室(1)");
                    if (T_Pictureurl_10 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "居室照片1", Value = T_Pictureurl_10.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "居室照片1", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_11 = obj.sitePicture.Find(p => p.T_SpName == "建筑外观");
                    if (T_Pictureurl_11 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "建筑外观照片", Value = T_Pictureurl_11.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "建筑外观照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_12 = obj.sitePicture.Find(p => p.T_SpName == "厨房");
                    if (T_Pictureurl_12 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "厨房照片", Value = T_Pictureurl_12.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "厨房照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_13 = obj.sitePicture.Find(p => p.T_SpName == "卫生间");
                    if (T_Pictureurl_13 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "卫生间照片", Value = T_Pictureurl_13.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "卫生间照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_14 = obj.sitePicture.Find(p => p.T_SpName == "阳台");
                    if (T_Pictureurl_14 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "阳台照片", Value = T_Pictureurl_14.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "阳台照片", Value = "暂无照片", Type = FileFormat.String });
                    }
                    var T_Pictureurl_15 = obj.sitePicture.Find(p => p.T_SpName == "客厅");
                    if (T_Pictureurl_15 != null)
                    {
                        lwt.Add(new WordsTemp() { Name = "客厅", Value = T_Pictureurl_15.T_Pictureurl, Type = FileFormat.Image });
                    }
                    else
                    {
                        lwt.Add(new WordsTemp() { Name = "客厅", Value = "暂无照片", Type = FileFormat.String });
                    }

                }

                if (obj.ownership != null)
                {
                    lwt.Add(new WordsTemp() { Name = "房屋所有权证书编号", Value = string.Format("《房屋所有权证》({0})", obj.ownership.T_OwneNumber) });
                    lwt.Add(new WordsTemp() { Name = "产权人", Value = obj.ownership.T_ProductionName });
                    lwt.Add(new WordsTemp() { Name = "共有情况", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.ownership.T_CommonSituation)) });
                    lwt.Add(new WordsTemp() { Name = "房屋产别", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.ownership.T_HousingProduction)) });
                    lwt.Add(new WordsTemp() { Name = "来源属性", Value = transmitHelper.getDictionaryNameByDictionaryID(Convert.ToInt32(obj.ownership.T_SourceAttribute)) });
                    lwt.Add(new WordsTemp() { Name = "专有建筑面积", Value = obj.ownership.T_ProperBuiltUpArea.ToString() });
                    lwt.Add(new WordsTemp() { Name = "房产证登记时间", Value = obj.ownership.T_ProductionDate != null ? ((DateTime)obj.ownership.T_ProductionDate).ToString("yyyy年MM月dd日") : "--" });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "房屋所有权证书编号", Value = "" });
                }

                if (obj.realestate != null)
                {
                    lwt.Add(new WordsTemp() { Name = "不动产权证书编号", Value = string.Format("《不动产权证书》（{0}）", obj.realestate.T_RealNumber) });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "不动产权证书编号", Value = "" });
                }

                if (obj.taxcertificate != null)
                {
                    lwt.Add(new WordsTemp() { Name = "国税收完税证明编号", Value = string.Format("中华人民共和国税收完税证明（141）{0}", obj.taxcertificate.T_TaxNumber) });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "国税收完税证明编号", Value = "" });
                }

                if (obj.businessContract != null)
                {
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同编号", Value = obj.businessContract.T_BusinessNumber });
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同签订时间", Value = obj.businessContract.T_BcDate != null ? ((DateTime)obj.businessContract.T_BcDate).ToString("yyyy年MM月dd日") : "--" });
                }
                else
                {
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同编号", Value = "--" });
                    lwt.Add(new WordsTemp() { Name = "存量房屋买卖合同签订时间", Value = "--" });
                }

                CommonWords.Word(TemplateName, path + SaveName, lwt);
                jm.code = 1;
                jm.msg = SaveName;
                return Json(jm);
            }
            else
            {
                jm.code = 0;
                jm.msg = "找不到报告类型对应的模板";
                return Json(jm);
            }
        }







    }
}
